/* 校验文章上传的参数 */
const Response = require("../util/respanse.js")
/* 参数校验 */
const paramsValidata = (req, res, next) => {
    try {

        let { album_name, description } = req.body
        let fleg = false
        let len = Object.entries(req.body).length
        console.log(!album_name || !description);
        if (!album_name || !description || len >= 3) {
            fleg = true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数不合法"
            })
        }
        if (!fleg) {
            next()
        }
    } catch (error) {
        console.log(error);
    }
}
/* 添加图片的校验 */
const paramsValidataPic = (req, res, next) => {
    try {
        let fleg = false
        let len = Object.entries(req.body).length
        let { aumble_id, file_namelist } = req.body
        if (!aumble_id || !file_namelist || len >= 3) {
            fleg = true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数不合法"
            })
        }
        if (!Array.isArray(file_namelist)) {
            fleg = true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数不合法"
            })
        }
        if (!fleg) {
            next()
        }
    } catch (error) {
        console.log(error);
    }
}
/* 分页器的校验 */
const paramsValidataGet = (req, res, next) => {
    try {
        let fleg = false
        let { page, pageSize } = req.body
        let len = Object.entries(req.body).length
        if (!page || !pageSize || len >= 4) {
            fleg =true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数不合法"
            })
        }
        if(!fleg){
            next()
        }
    } catch (error) {
        console.log(error);
        
    }
}
module.exports = {
    paramsValidata,
    paramsValidataPic,
    paramsValidataGet
}